<%if(id){%>
<% var dr = daily_stats.recharge || {},
    dp = daily_stats.pay || {},
    daily_withdraw = daily_stats.withdraw || {},
    db = daily_stats.bonus || {},
    df = daily_stats.refund || {},
    dw = daily_stats.win || {},
    dc = daily_stats.coupon || {},

    ur = user_stats.recharge || {},
    up = user_stats.pay || {},
    uw = user_stats.win || {},
    ub = user_stats.bonus || {},
    uf = user_stats.refund || {},
    uc = user_stats.coupon || {},
    user_withdraw = user_stats.withdraw || {};
    ex = JSON.parse(extend) || {},
    unused = coupon_stats.unused || {},
    used = coupon_stats.used || {},
    expired = coupon_stats.expired || {};
    sys_total_amount = parseFloat(used.amount || 0)+parseFloat(system_amount || 0);
    total_amount_gain = parseFloat(ur.total || 0) - parseFloat(user_withdraw.total || 0) - parseFloat(user_withdraw.total_wait || 0) - parseFloat(user_withdraw.total_forbidden || 0) - parseFloat(balance || 0)- sys_total_amount;

%>
<div class="pv30 ph40 bg-light dark br-b br-grey posr">
    <div class="table-layout">
        <div class="w200 text-center pr30 hidden-xs">
            <img src="<%= avatar_id %>" alt="头像" class="fix-icon">
        </div>
        <div class="va-t m30">
            <div class="row">
                <div class="col-md-4">
                    <dl class="dl-horizontal">
                        <dt>用户ID</dt>
                        <dd>
                            <%= id %>
                        </dd>
                        <dt>用户昵称</dt>
                        <dd>
                            <%= user_name %>
                        </dd>
                        <dt>最后登陆ip</dt>
                        <dd>
                            <%= ip || "未知" %>
                        </dd>
                        <dt>注册ip</dt>
                        <dd>
                            <%= ex.ip || "未知"%>
                        </dd>
                        <dt>地区</dt>
                        <dd>
                            <%= addr || "未知" %>
                        </dd>
                        <dt>设备ID</dt>
                        <dd>
                            <%= user_stats.aid || "none" %>
                        </dd>
                        <dt>注册渠道</dt>
                        <dd>
                            <%= user_stats.chn || "none" %>
                        </dd>
                        <!--
                        <dt>姓名</dt>
                        <dd>
                            <%= name || "未知" %>
                        </dd>
                        <dt>身份证号</dt>
                        <dd>
                            <%= citizen_id || "未知" %>
                        </dd>
                         -->
                    </dl>
                </div>
                <div class="col-md-4">
                    <dl class="dl-horizontal">
                        <dt>绑定手机号</dt>
                        <dd>
                            <%= phone %>
                        </dd>
                        <dt>余额</dt>
                        <dd>
                            <%= parseFloat(balance || 0).toFixed(2) %>元
                        </dd>
                        <dt>可提现金额</dt>
                        <dd>
                            <%= parseFloat(withdraw || 0).toFixed(2) %>元
                        </dd>
                        <dt>可用红包</dt>
                        <dd>
                            <%= unused.amount %>元
                        </dd>
                        <dt>已用红包</dt>
                        <dd>
                            <%= used.amount %>元
                        </dd>
                        <dt>系统上分</dt>
                        <dd>
                            <%= parseFloat(system_amount || 0) %>元
                        </dd>
                        <dt>活动奖励</dt>
                        <dd>
                            0元
                        </dd>


                    </dl>
                </div>
                <div class="col-md-4">
                    <dl class="dl-horizontal">
                        <dt>绑定支付宝</dt>
                        <dd>
                            <%= alipay || '未绑定' %>
                        </dd>
                        <dt>绑定银行卡</dt>
                        <dd>
                            <%= bank_card || '未绑定' %>
                        </dd>
                        <dt>绑定微信</dt>
                        <dd>
                            <%= wechat || '未绑定' %>
                        </dd>
                        <dt>注册时间</dt>
                        <dd>
                            <%= created_at %>
                        </dd>
                        <dt>最后活跃时间</dt>
                        <dd>
                            <%= user_stats.updated_at %>
                        </dd>
                        <dt>累计活跃天数</dt>
                        <dd>
                            <%= active_days || 0 %>
                        </dd>
                    </dl>
                </div>
                <div class="col-md-8">
                    <% if(status == 1024){ %>
                    <span class="label label-danger">黑名单用户</span>
                    <% } else{ %>
                    <button class="btn btn-default btn-sm" onclick="addBlack(<%= id %>);">加入黑名单</button>
                    <% } %>
                    <% if(!black_uid){ %>
                    <button class="btn btn-default btn-sm" onclick="add_withdraw_black(<%= id %>, 'black_uid');">加入提现黑名单</button>
                    <% } else{ %>
                    <span class="label label-danger">提现黑名单用户</span>
                    <% } %>
                    <% if(!test_uid){ %>
                    <button class="btn btn-default btn-sm" onclick="add_withdraw_black(<%= id %>, 'test_uid');">加入提现测试黑名单</button>
                    <% } else{ %>
                    <span class="label label-danger">测试用户</span>
                    <% } %>
                    <% if(phone){ %>
                    <button class="btn btn-default btn-sm" onclick="reset_user_phone(<%= id %>);">解绑手机号</button>
                    <% } %>
                    <% if(alipay){ %>
                    <button class="btn btn-default btn-sm" onclick="unbind_financial_account(<%= id %>, 'alipay');">解绑支付宝</button>
                    <% } %>
                    <% if(bank_card){ %>
                    <button class="btn btn-default btn-sm" onclick="unbind_financial_account(<%= id %>, 'bank_card');">解绑银行卡</button>
                    <% } %>
                    <% if(wechat){ %>
                    <button class="btn btn-default btn-sm" onclick="unbind_financial_account(<%= id %>, 'wechat');">解绑微信</button>
                    <% } %>
                </div>
            </div>
        </div>
    </div>
</div>

<div class="p25 pt35">
    <div class="col-md-12">
        <div class="panel">
            <div class="panel-heading">
					<span class="panel-icon"><i class="fa fa-star text-primary"></i>
                    </span>
                <span class="panel-title">充值／提现数据</span>
            </div>
            <div class="panel-body">
                <div class="col-md-6">
                    <div class="col-md-12">
                        <div class="panel">
                            <div class="panel-heading">
                                <span class="panel-title">累计数据</span>
                            </div>
                            <div class="panel-body">
                                <div class="col-md-6">
                                    <dt>充值总额：<%= (ur.total || 0).toFixed(2) %></dt>
                                    <dt>充值次数：<%= ur.count || 0 %></dt>
                                    <% for(var k in ur){ %>
                                    <% if(k!='total' && k!='count' && k!='last_at'){ %>
                                    <dt>
                                        <%= k %>：<%= ur[k] %>
                                    </dt>
                                    <% } %>
                                    <% } %>
                                </div>
                                <div class="col-md-6">
                                    <dt>已提现金额：<%= user_withdraw.total || 0 %></dt>
                                    <dt>已提现次数：<%= user_withdraw.count || 0 %></dt>
                                    <dt>待提现金额：<%= user_withdraw.total_wait || 0 %></dt>
                                    <dt>待提现次数：<%= user_withdraw.count_wait || 0 %></dt>
                                    <dt>禁止提现金额：<%= user_withdraw.total_forbidden || 0 %></dt>
                                    <dt>禁止提现次数：<%= user_withdraw.count_forbidden || 0 %></dt>
                                    <dt>盈利金额：<%= ( -1 * ((ur.total || 0) - (user_withdraw.total || 0) -
                                        (user_withdraw.total_wait || 0) - (user_withdraw.total_forbidden || 0) -
                                        balance)).toFixed(2) %></dt>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
                <div class="col-md-6">
                    <div class="col-md-12">
                        <div class="panel">
                            <div class="panel-heading">
                                <span class="panel-title">今日数据</span>
                            </div>
                            <div class="panel-body">
                                <div class="col-md-6">
                                    <dt>充值总额：<%= (dr.total || 0).toFixed(2) %></dt>
                                    <dt>充值次数：<%= dr.count || 0 %></dt>
                                    <% for(var k in dr){ %>
                                    <% if(k!='total' && k!='count' && k!='last_at'){ %>
                                    <dt>
                                        <%= k %>：<%= dr[k] %>
                                    </dt>
                                    <% } %>
                                    <% } %>
                                </div>
                                <div class="col-md-6">
                                    <dt>已提现金额：<%= daily_withdraw.total || 0 %></dt>
                                    <dt>已提现次数：<%= daily_withdraw.count || 0 %></dt>
                                    <dt>待提现金额：<%= daily_withdraw.total_wait || 0 %></dt>
                                    <dt>待提现次数：<%= daily_withdraw.count_wait || 0 %></dt>
                                    <dt>禁止提现金额：<%= daily_withdraw.total_forbidden || 0 %></dt>
                                    <dt>禁止提现次数：<%= daily_withdraw.count_forbidden || 0 %></dt>
                                    <dt>盈利金额：<%= ( -1 * ((dr.total || 0) - (daily_withdraw.total || 0) - (daily_withdraw.total_wait || 0))).toFixed(2) %></dt>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>
<div class="p25 pt35">
    <div class="col-md-12">
        <div class="panel">
            <div class="panel-heading">
					<span class="panel-icon"><i class="fa fa-star text-primary"></i>
                    </span>
                <span class="panel-title">购彩数据</span>
            </div>

            <div class="panel-body">
                <div class="col-md-6">
                    <div class="col-md-12">
                        <div class="panel">
                            <div class="panel-heading">
                                <span class="panel-title">累计数据</span>
                            </div>
                            <div class="panel-body">
                                <div class="col-md-6">
                                    <dt>购彩金额：<%= (up.total || 0).toFixed(2) %></dt>
                                    <dt>购彩次数：<%= (up.count || 0).toFixed(0) %></dt>
                                    <dt>有效投注：<%= (up.total || 0).toFixed(2) - (uf.total || 0).toFixed(2) %></dt>
                                    <dt>退款总额：<%= (uf.total || 0).toFixed(2) %></dt>
                                </div>
                                <div class="col-md-6">
                                    <dt>中奖金额：<%= (uw.total || 0).toFixed(2) %></dt>
                                    <dt>加奖金额：<%= (ub.total || 0).toFixed(2) %></dt>
                                    <dt>购彩盈利：<%= ((uw.total || 0) + (ub.total || 0) + (uf.total || 0)
                                                    - (up.total || 0)).toFixed(2) %></dt>
                                </div>
                                <div id="pay-dist"></div>
                            </div>
                        </div>
                    </div>
                </div>
                <div class="col-md-6">
                    <div class="col-md-12">
                        <div class="panel">
                            <div class="panel-heading">
                                <span class="panel-title">今日数据</span>
                            </div>
                            <div class="panel-body">
                                <div class="col-md-6">
                                    <dt>购彩金额：<%= (dp.total || 0).toFixed(2) %></dt>
                                    <dt>购彩次数：<%= (dp.count || 0).toFixed(0) %></dt>
                                    <dt>有效投注：<%= (dp.total || 0).toFixed(2) - (df.total || 0).toFixed(2) %></dt>
                                    <dt>退款总额：<%= (df.total || 0).toFixed(2) %></dt>
                                </div>
                                <div class="col-md-6">
                                    <dt>中奖金额：<%= (dw.total || 0).toFixed(2) %></dt>
                                    <dt>加奖金额：<%= (db.total || 0).toFixed(2) %></dt>
                                    <dt>购彩盈利：<%= ((dw.total || 0) + (db.total || 0) + (df.total || 0)
                                                     - (dp.total || 0)).toFixed(2) %></dt>
                                </div>
                                <div id="daily-pay-dist"></div>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>
                <% var ul = user_stats.lottery || {},
                uk = user_stats.kfc || {},
                uf = user_stats.fruit || {},
                ub = user_stats.bull || {}; %>

                <% var dl = daily_stats.lottery || {},
                dk = daily_stats.kfc || {},
                df = daily_stats.fruit || {},
                db = daily_stats.bull || {};
                %>
<div class="p25 pt35">
    <div class="col-md-12">
        <div class="panel">
            <div class="panel-heading">
					<span class="panel-icon"><i class="fa fa-star text-primary"></i>
                    </span>
                <span class="panel-title">电玩城数据</span>
            </div>

            <div class="panel-body">
                <div class="col-md-6">
                    <div class="col-md-12">
                        <div class="panel">
                            <div class="panel-heading">

                                <span class="panel-title">累计数据</span>

                            </div>
                            <div class="panel-body">
                                <div class="col-md-5">
                                    <dt>参与金额：
                                        <%= ((ul.bet_amount || 0) + (ub.bet_amount || 0) +
                                        (uk.bet_amount || 0) + (uf.bet_amount || 0)).toFixed(2) %>
                                    </dt>
                                    <dt>参与次数：
                                        <%= ((ul.bet_count || 0) + (ub.bet_count || 0) +
                                        (uk.bet_count || 0) + (uf.bet_count || 0)).toFixed(2) %>
                                    </dt>
                                    <dt>中奖次数：
                                        <%= ((ul.win_count || 0) + (ub.win_count || 0) +
                                        (uk.win_count || 0) + (uf.win_count || 0)).toFixed(2) %>
                                    </dt>
                                    <dt>中奖金额：
                                        <%= ((ul.win_amount || 0) + (ub.win_amount || 0) + (ub.lose_amount || 0) +
                                        (uk.award_amount || 0) + (uf.win_amount || 0)).toFixed(2) %>
                                    </dt>
                                    <dt>电玩城盈利：
                                        <%= ((ul.gain_amount || 0) + (ub.gain_amount || 0) +
                                        (uk.gain_amount || 0) + (uf.gain_amount || 0)).toFixed(2) %>
                                    </dt>
                                </div>
                                <div class="col-md-7">
                                    <dt>转盘参与／盈利：<%= (ul.bet_amount || 0).toFixed(2) %>／<%= (ul.gain_amount || 0).toFixed(2) %></dt>
                                    <dt>牛牛参与／盈利：<%= (ub.bet_amount || 0).toFixed(2) %>／<%= (ub.gain_amount || 0).toFixed(2) %></dt>
                                    <dt>slot参与／盈利：<%= (uk.bet_amount || 0).toFixed(2) %>／<%= (uk.gain_amount || 0).toFixed(2) %></dt>
                                    <dt>水果参与／盈利：<%= (uf.bet_amount || 0).toFixed(2) %>／<%= (uf.gain_amount || 0).toFixed(2) %></dt>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
                <div class="col-md-6">
                    <div class="col-md-12">
                        <div class="panel">
                            <div class="panel-heading">
                                <span class="panel-title">今日数据</span>
                            </div>
                            <div class="panel-body">
                                <div class="col-md-5">
                                    <dt>参与金额：
                                        <%= ((dl.bet_amount || 0) + (db.bet_amount || 0) +
                                        (dk.bet_amount || 0) + (df.bet_amount || 0)).toFixed(2) %>
                                    </dt>
                                    <dt>参与次数：
                                        <%= ((dl.bet_count || 0) + (db.bet_count || 0) +
                                        (dk.bet_count || 0) + (df.bet_count || 0)).toFixed(2) %>
                                    </dt>
                                    <dt>中奖次数：
                                        <%= ((dl.win_count || 0) + (db.win_count || 0) +
                                        (dk.win_count || 0) + (df.win_count || 0)).toFixed(2) %>
                                    </dt>
                                    <dt>中奖金额：
                                        <%= ((dl.win_amount || 0) + (db.win_amount || 0) + (db.lose_amount || 0) +
                                        (dk.win_amount || 0) + (df.win_amount || 0)).toFixed(2) %>
                                    </dt>
                                    <dt>电玩城盈利：
                                        <%= ((dl.gain_amount || 0) + (db.gain_amount || 0) +
                                        (dk.gain_amount || 0) + (df.gain_amount || 0)).toFixed(2) %>
                                    </dt>
                                </div>
                                <div class="col-md-7">
                                    <dt>转盘参与／盈利：<%= (dl.bet_amount || 0).toFixed(2) %>／<%= (dl.gain_amount || 0).toFixed(2) %></dt>
                                    <dt>牛牛参与／盈利：<%= (db.bet_amount || 0).toFixed(2) %>／<%= (db.gain_amount || 0).toFixed(2) %></dt>
                                    <dt>slot参与／盈利：<%= (dk.bet_amount || 0).toFixed(2) %>／<%= (dk.gain_amount || 0).toFixed(2) %></dt>
                                    <dt>水果参与／盈利：<%= (df.bet_amount || 0).toFixed(2) %>／<%= (df.gain_amount || 0).toFixed(2) %></dt>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>
<% var dm = daily_stats.metis || {},
       um = user_stats.metis || {},
       daily_total_metis_bet = 0,
       daily_total_metis_profit = 0,
       user_total_metis_bet = 0,
       user_total_metis_profit = 0;
    _.each(METIS_GAME_TYPE, function(key, metis_type){
        daily_total_metis_bet += (dm[metis_type.toString() + '_bet_amount'] || 0);
        daily_total_metis_profit += (dm[metis_type.toString() + '_total_profit'] || 0);
        user_total_metis_bet += (um[metis_type.toString() + '_bet_amount'] || 0);
        user_total_metis_profit += (um[metis_type.toString() + '_total_profit'] || 0);
    });
%>

<div class="p25 pt35">
    <div class="col-md-12">
        <div class="panel">
            <div class="panel-heading">
					<span class="panel-icon"><i class="fa fa-star text-primary"></i>
                    </span>
                <span class="panel-title">Metis数据</span>
            </div>

            <div class="panel-body">
                <div class="col-md-6">
                    <div class="col-md-12">
                        <div class="panel">
                            <div class="panel-heading">
                                <span class="panel-title">累计数据</span>
                            </div>
                            <div class="panel-body">
                                <div class="col-md-5">
                                    <dt>参与金额：
                                        <%= (user_total_metis_bet).toFixed(2) %>
                                    </dt>
                                    <dt>中奖金额：
                                        <%= (user_total_metis_bet + user_total_metis_profit).toFixed(2) %>
                                    </dt>
                                    <dt>Metis盈利：
                                        <%= (user_total_metis_profit).toFixed(2) %>
                                    </dt>
                                </div>
                                <div class="col-md-7">
                                    <dt>龙虎参与／盈利：<%= (um['5503_bet_amount'] || 0).toFixed(2) %>／<%= (um['5503_total_profit'] || 0).toFixed(2) %></dt>
                                    <dt>超级6参与／盈利：<%= (um['5502_bet_amount'] || 0).toFixed(2) %>／<%= (um['5502_total_profit'] || 0).toFixed(2) %></dt>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
                <div class="col-md-6">
                    <div class="col-md-12">
                        <div class="panel">
                            <div class="panel-heading">
                                <span class="panel-title">今日数据</span>
                            </div>
                            <div class="panel-body">
                                <div class="col-md-5">
                                    <dt>参与金额：
                                        <%= (daily_total_metis_bet).toFixed(2) %>
                                    </dt>
                                    <dt>中奖金额：
                                        <%= (daily_total_metis_bet + daily_total_metis_profit).toFixed(2) %>
                                    </dt>
                                    <dt>Metis盈利：
                                        <%= (daily_total_metis_profit).toFixed(2) %>
                                    </dt>
                                </div>
                                <div class="col-md-7">
                                    <dt>龙虎参与／盈利：<%= (dm['5503_bet_amount'] || 0).toFixed(2) %>／<%= (dm['5503_total_profit'] || 0).toFixed(2) %></dt>
                                    <dt>超级6参与／盈利：<%= (dm['5502_bet_amount'] || 0).toFixed(2) %>／<%= (dm['5502_total_profit'] || 0).toFixed(2) %></dt>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>
<%}else{%>
<h3 class="text-danger">用户不存在！</h3>
<%}%>


<!-- 封号复选框 -->
<div id="AccountBlackDialog" class="withdraw-limit-dialog" style="display:none">
    <div class="content">
        <span class="withdraw-limit" id = "account_id"></span>
        <span class="withdraw-limit">请输入封号理由:</span>
        <div>
            <input id="black-content" type="text" placeholder="">
        </div>
        <div class="">
            <button id="closeBtn" onclick="closeAccountBlackDialog()" type="button" class="btn btn-danger">关闭</button>
            <button id="saveBtn" onclick="accountBlack()" type="button" class="btn btn-success">确定</button>
        </div>
    </div>
</div>

<script>

    function addBlack(user_id) {
        $('#account_id').text(user_id);
        $("#AccountBlackDialog").show();
     }

    function closeAccountBlackDialog() {
        $("#AccountBlackDialog").hide();
    }

    function accountBlack(user_id){
        user_id = $('#account_id').text();
        reason = $('#black-content').val();
        var data = {'account_id': user_id,'status': 'BLACK',"reason":reason};
        var json_data = JSON.stringify(data);
        $.ajax({
            url: '/admin/account/set_black_account/',
            type: 'POST',
            headers: {
                'X-AUTH-USER': getCookie('bigbang_user_id'),
                'X-AUTH-TOKEN': getCookie('bigbang_user_token')
            },
            data: json_data
        }).done(function (resp) {
            alert('加入黑名单成功！');
            location.reload();
            account_black.closeAccountBlackDialog();
            console.log(JSON.stringify(resp));
        }).fail(function (resp) {
            alert('加入黑名单失败！');
            console.log(JSON.stringify(resp));
        });
    }
    function getCookie(name) {
        var cookieName = name + "=";
        var cookies = document.cookie.split(';');
        for (var i = 0; i < cookies.length; i++) {
            var c = cookies[i];
            while (c.charAt(0) == ' ') c = c.substring(1);
            if (c.indexOf(cookieName) != -1) return c.substring(cookieName.length, c.length);
        }
        return "";
    }

    function reset_user_phone(user_id){
        var reason = window.prompt("请填写操作原因");
        if (!reason) {
            alert("操作原因不能为空");
        }else{
            $.post('/admin/user/reset_user_phone/', {'id': user_id, 'reason': reason}, function(data){
                alert('已解绑');
            });
        }
    }
    function unbind_financial_account(user_id, type){
        var reason = window.prompt("请填写操作原因");
        if (!reason) {
            alert("操作原因不能为空");
        }else{
            $.post('/admin/user/financial_account/unbind/', {'user_id': user_id, 'account_type': type, 'reason': reason}, function(data){
                alert('已解绑');
            });
        }
    }
    function add_withdraw_black(user_id, type) {
        var reason = window.prompt("请填写操作原因");
        if (!reason) {
            alert("操作原因不能为空");
        }else{
            $.post('/admin/withdraw/black/set/', JSON.stringify({
                                'type': type,
                                'type_account': user_id.toString(),
                                'status':1,
                                'reason':reason
                            }), function(data){
                location.reload();
                alert('加入提现黑名单成功！');
            });
        }
    }
</script>
